package com.yangchuang.openpicture.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.yangchuang.openpicture.property.OSSProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 阿里云OSS配置类
 */
@Slf4j
@Configuration
public class OSSConfiguration {
    private final OSSProperties ossProperties;

    public OSSConfiguration(OSSProperties ossProperties) {
        this.ossProperties = ossProperties;
    }

    /**
     * 创建OSS客户端
     * 
     * @return OSS客户端实例
     */
    @Bean
    public OSS ossClient() {
        log.info("初始化OSS客户端，endpoint: {}, bucketName: {}", 
                ossProperties.getEndpoint(), ossProperties.getBucketName());
        
        // 创建OSSClient实例
        OSS ossClient = new OSSClientBuilder().build(
                ossProperties.getEndpoint(),
                ossProperties.getAccessKeyId(),
                ossProperties.getAccessKeySecret()
        );
        
        log.info("OSS客户端初始化成功");
        return ossClient;
    }
}